package com.lsy.weizhi2.fragment;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.location.BDLocation;
import com.baidu.location.BDLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;
import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapBaseIndoorMapInfo;
import com.baidu.mapapi.map.MapPoi;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapStatusUpdate;
import com.baidu.mapapi.map.MapStatusUpdateFactory;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.Marker;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.MyLocationConfiguration;
import com.baidu.mapapi.map.MyLocationData;
import com.baidu.mapapi.model.LatLng;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.google.gson.Gson;
import com.lsy.weizhi2.JsonObject.DiTu;
import com.lsy.weizhi2.R;
import com.lsy.weizhi2.activity.CustomPage;
import com.lsy.weizhi2.activity.LoginActivty;
import com.lsy.weizhi2.activity.MySelfMessage2;
import com.lsy.weizhi2.activity.NoteDetail;
import com.lsy.weizhi2.config.Constants;
import com.lsy.weizhi2.config.CostomFlag;
import com.lsy.weizhi2.config.MyHeight;
import com.lsy.weizhi2.config.MyInfo;
import com.lsy.weizhi2.mybase.BaseApp;
import com.lsy.weizhi2.mybase.MyTitleView2;
import com.lsy.weizhi2.myutils.DaShangPopupCall;
import com.lsy.weizhi2.myutils.ManagerItem;
import com.lsy.weizhi2.myutils.TitleViewCall;
import com.lsy.weizhi2.popupwindow.DaShangPopup;
import com.lsy.weizhi2.popupwindow.NearbyPopup;
import com.lsy.weizhi2.third.BaseStripAdapter;
import com.lsy.weizhi2.third.LocationService;
import com.lsy.weizhi2.third.StripListView;
import com.lsy.weizhi2.utils.BitmapUtils;
import com.lsy.weizhi2.utils.MapHelp;
import com.lsy.weizhi2.utils.MathHelper;
import com.lsy.weizhi2.utils.MyMethod;
import com.lsy.weizhi2.utils.MyOkHttpUtils;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 嗨哟 on 2017/3/13.
 */
public class FuJingFragment extends Fragment {
    private Context context;
    // 定位相关
    LocationClient mLocClient;
    public MyLocationListenner myListener = new MyLocationListenner();
    private MyLocationConfiguration.LocationMode mCurrentMode;
    BitmapDescriptor mCurrentMarker;
    MapView mMapView;
    BaiduMap mBaiduMap;
    View mainview;
    StripListView stripListView;
    BaseStripAdapter mFloorListAdapter;
    MapBaseIndoorMapInfo mMapBaseIndoorMapInfo = null;
    boolean isFirstLoc = true; // 是否首次定位
    private LocationService locationService;
    private DaShangPopup daShangPopup;
    private int orderId,friendId;

    private RelativeLayout fujing_rl;
    private LinearLayout zoom_ll;
    private TextView current_tv;
    private MyTitleView2 fujing_title;
    private ImageButton jia, jian;
    private NearbyPopup nearbyPopup;
    //搜索用的标签
    public static int first,second;
    public static String name;
    private static double latitude,longitude;

    private BitmapDescriptor bitmap1,bitmap2;

    private List<DiTu.DataBean> list_dt;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if(msg.what==1){
                MapHelp mapHelp= (MapHelp) msg.obj;
                MarkerOptions markerOptions11 = new MarkerOptions()
                        .position(new LatLng(mapHelp.getLat(), mapHelp.getLng()))
                        .icon(mapHelp.getBd());
                Log.i("FuJingFragment","lat=h="+mapHelp.getLat()+"\nlng=h="+ mapHelp.getLng());
                mBaiduMap.addOverlay(markerOptions11);
            }
        }
    };
    boolean ifFrist;
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        locationService = BaseApp.locationService;
    }

    ArrayList<BitmapDescriptor> list_images;
    private void navigateTo(double lat,double lng) {
        // 按照经纬度确定地图位置
        if (ifFrist) {
            LatLng ll = new LatLng(lat,
                    lng);
            MapStatusUpdate update = MapStatusUpdateFactory.newLatLng(ll);
            // 移动到某经纬度
            mBaiduMap.animateMapStatus(update);
            update = MapStatusUpdateFactory.zoomBy(5f);
            // 放大
            mBaiduMap.animateMapStatus(update);

            ifFrist = false;
        }
    }
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mainview = inflater.inflate(R.layout.fujin_fragment, container, false);
        list_images = new ArrayList<>();
        list_dt = new ArrayList<>();
        daShangPopup = new DaShangPopup();
        // 地图初始化
        mMapView = (MapView) mainview.findViewById(R.id.bmapView);
        mBaiduMap = mMapView.getMap();
        //隐藏缩放控件
        mMapView.showZoomControls(false);
        //隐藏百度logo
        mMapView.removeViewAt(1);
        // 开启定位图层
        mBaiduMap.setMyLocationEnabled(true);
        // 开启室内图
        mBaiduMap.setIndoorEnable(true);
        mBaiduMap.clear();
        // 定位初始化
        // LatLng latLng=new LatLng();
        // MarkerOptions options=new MarkerOptions().icon()
        mLocClient = new LocationClient(BaseApp.context);
        mLocClient.registerLocationListener(myListener);
        LocationClientOption option = new LocationClientOption();
        option.setOpenGps(true); // 打开gps
        option.setCoorType("bd09ll"); // 设置坐标类型
        option.setScanSpan(3000);
        mLocClient.setLocOption(option);
        mLocClient.start();
        stripListView = new StripListView(getActivity());
        container.addView(stripListView);
        mFloorListAdapter = new BaseStripAdapter(getActivity());
        bitmap1 = BitmapDescriptorFactory.fromResource(R.mipmap.nearby_self);
        bitmap2 = BitmapDescriptorFactory.fromResource(R.mipmap.touxiang);

        navigateTo(MyInfo.Latitude,MyInfo.Longitude);
        //根据位置加载图像
        MarkerOptions markerOptions = new MarkerOptions()
                .position(new LatLng(latitude, longitude))
                .icon(bitmap1).zIndex(3);

        mBaiduMap.addOverlay(markerOptions);


        mBaiduMap.setOnBaseIndoorMapListener(new BaiduMap.OnBaseIndoorMapListener() {
            @Override
            public void onBaseIndoorMapMode(boolean b, MapBaseIndoorMapInfo mapBaseIndoorMapInfo) {
                if (b == false || mapBaseIndoorMapInfo == null) {
                    stripListView.setVisibility(View.INVISIBLE);

                    return;
                }

                mFloorListAdapter.setmFloorList(mapBaseIndoorMapInfo.getFloors());
                stripListView.setVisibility(View.VISIBLE);
                stripListView.setStripAdapter(mFloorListAdapter);
                mMapBaseIndoorMapInfo = mapBaseIndoorMapInfo;
            }
        });
        //地图点击事件监听
        mBaiduMap.setOnMapClickListener(new BaiduMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                mBaiduMap.clear();
                mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
                mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true,
                        mCurrentMarker));
                latitude=latLng.latitude;
                longitude=latLng.longitude;
                MarkerOptions markerOptions = new MarkerOptions()
                        .position(latLng)
                        .icon(bitmap1);
                mBaiduMap.addOverlay(markerOptions);
                getFuJing();//地图点击事件
            }

            @Override
            public boolean onMapPoiClick(MapPoi mapPoi) {
                return false;
            }
        });
        //标志点击事件监听
        mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {
                double lat = marker.getPosition().latitude;
                double lng = marker.getPosition().longitude;
                lat=MathHelper.SplitAndRound(lat,7);
                lng=MathHelper.SplitAndRound(lng,7);
                Log.i("FuJingFragment","latitude=m="+lat+"\nlongitude=m="+lng);
                if (list_dt != null && list_dt.size() != 0) {
                    for (int i = 0; i < list_dt.size(); i++) {
                        if (list_dt.get(i).getLatitude() == lat && list_dt.get(i).getLongitude() == lng) {
                            Log.i("FuJingFragment","true");
                            Log.i("FuJingFragment","list=1="+list_dt.get(i).getLatitude()+"\n"+list_dt.get(i).getLongitude());
                            Log.i("FuJingFragment","list=2="+lat+"\n"+lng);
                            nearbyPopup.init(context, fujing_rl, list_dt.get(i));
                            orderId=list_dt.get(i).getId();
                            friendId=list_dt.get(i).getCreateUserId();
                        }
                    }
                }

                return false;
            }
        });
        /**
         * 自定义控件find
         */
        fujing_rl = (RelativeLayout) mainview.findViewById(R.id.fujing_rl);
        zoom_ll = (LinearLayout) mainview.findViewById(R.id.zoom_ll);
        fujing_title = (MyTitleView2) mainview.findViewById(R.id.fujing_title);
        current_tv = (TextView) mainview.findViewById(R.id.current_tv);
        jia = (ImageButton) mainview.findViewById(R.id.jia);
        jian = (ImageButton) mainview.findViewById(R.id.jian);
        nearbyPopup = new NearbyPopup();
        nearbyPopup.setDaShangPopupCall(new DaShangPopupCall() {
            @Override
            public void dismissListener() {

            }

            @Override
            public void connect(View view, int flag) {
                if(flag==DaShangPopupCall.CONNECT){
                    TellPhone(orderId);
                }
            }

            @Override
            public void yuyue(String str) {
                MyMethod.toActivity(context, NoteDetail.class,new String[]{"json","tag"},new String[]{str, ManagerItem.WeiZhi+""});
            }

            @Override
            public void jubao(String msg, int orderReplyId) {

            }
        });
        daShangPopup.setDaShangPopupCall(new DaShangPopupCall() {
            @Override
            public void dismissListener() {

            }

            @Override
            public void connect(View view, int flag) {
                String btn=daShangPopup.getBtn();
                if(btn.equals("一键拨号")){
                    MyMethod.CallPhone(context,daShangPopup.getPhone());
                }else if(btn.equals("私信联系")){
                    MyMethod.toActivity(context,MySelfMessage2.class,new String[]{"friendId"},new String[]{friendId+""});
                    daShangPopup.dismiss();
                }
            }

            @Override
            public void yuyue(String str) {

            }

            @Override
            public void jubao(String msg, int orderReplyId) {

            }
        });
        return mainview;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        context = getActivity();
        current_tv.setText(MyInfo.Address);
        current_tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mBaiduMap.clear();
                MarkerOptions markerOptions = new MarkerOptions()
                        .position(new LatLng(MyInfo.Latitude,MyInfo.Longitude))
                        .icon(bitmap1);
                mBaiduMap.addOverlay(markerOptions);
                current_tv.setText(MyInfo.Address);
                mCurrentMode = MyLocationConfiguration.LocationMode.FOLLOWING;
                mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(mCurrentMode, true,
                        mCurrentMarker));
                getFuJing();//回到当前位置
            }
        });
        jia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                float zoomLevel = mBaiduMap.getMapStatus().zoom;
                if (zoomLevel <= 18) {
                    mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomIn());
                    jia.setEnabled(true);
                } else {
                    MyMethod.showToast(context, "已经放至最大！");
                    jia.setEnabled(false);
                }
            }
        });
        jian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                float zoomLevel = mBaiduMap.getMapStatus().zoom;

                if (zoomLevel > 4) {
                    mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomOut());
                    jian.setEnabled(true);
                } else {
                    MyMethod.showToast(context, "已经缩至最小！");
                    jian.setEnabled(false);
                }
            }
        });
    }


    /**
     * 定位SDK监听函数
     */
    public class MyLocationListenner implements BDLocationListener {

        private String lastFloor = null;

        @Override
        public void onReceiveLocation(BDLocation location) {
            // map view 销毁后不在处理新接收的位置
            if (location == null || mMapView == null) {
                return;
            }
            String bid = location.getBuildingID();
            if (bid != null && mMapBaseIndoorMapInfo != null) {
                Log.i("indoor", "bid = " + bid + " mid = " + mMapBaseIndoorMapInfo.getID());
                if (bid.equals(mMapBaseIndoorMapInfo.getID())) {// 校验是否满足室内定位模式开启条件
                    // Log.i("indoor","bid = mMapBaseIndoorMapInfo.getID()");
                    String floor = location.getFloor().toUpperCase();// 楼层
                    Log.i("indoor", "floor = " + floor + " position = " + mFloorListAdapter.getPosition(floor));
                    Log.i("indoor", "radius = " + location.getRadius() + " type = " + location.getNetworkLocationType());

                    boolean needUpdateFloor = true;
                    if (lastFloor == null) {
                        lastFloor = floor;
                    } else {
                        if (lastFloor.equals(floor)) {
                            needUpdateFloor = false;
                        } else {
                            lastFloor = floor;
                        }
                    }
                    if (needUpdateFloor) {// 切换楼层
                        mBaiduMap.switchBaseIndoorMapFloor(floor, mMapBaseIndoorMapInfo.getID());
                        mFloorListAdapter.setSelectedPostion(mFloorListAdapter.getPosition(floor));
                        mFloorListAdapter.notifyDataSetInvalidated();
                    }

                    if (!location.isIndoorLocMode()) {
                        mLocClient.startIndoorMode();// 开启室内定位模式，只有支持室内定位功能的定位SDK版本才能调用该接口
                        Log.i("indoor", "start indoormod");
                    }
                }
            }

            MyLocationData locData = new MyLocationData.Builder().accuracy(location.getRadius())
                    // 此处设置开发者获取到的方向信息，顺时针0-360
                    .direction(100).latitude(location.getLatitude()).longitude(location.getLongitude()).build();
            mBaiduMap.setMyLocationData(locData);
            if (isFirstLoc) {
                isFirstLoc = false;
                LatLng ll = new LatLng(location.getLatitude(), location.getLongitude());
                MapStatus.Builder builder = new MapStatus.Builder();
                builder.target(ll).zoom(18.0f);
                mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build()));
            }
        }

        @Override
        public void onConnectHotSpotMessage(String s, int i) {

        }

        public void onReceivePoi(BDLocation poiLocation) {
        }
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onStop() {
        super.onStop();
        name=null;
    }

    @Override
    public void onPause() {
        mMapView.onPause();
        super.onPause();
        if (locationService != null) {
            Log.i("HomePage", "开始关闭");
            locationService.unregisterListener(MyInfo.mListener); //注销掉监听
            locationService.stop(); //停止定位服务
        }
    }

    int xx, ll_left, ll_top;

    @Override
    public void onResume() {
        mMapView.onResume();
        super.onResume();
        fujing_title.setSearch_ib(R.mipmap.search);
        //获取locationservice实例，建议应用中只初始化1个location实例，然后使用，可以参考其他示例的activity，都是通过此种方式获取locationservice实例的
        MyInfo.x = 1;
        locationService.registerListener(MyInfo.mListener);
        locationService.setLocationOption(locationService.getDefaultLocationClientOption());
        locationService.start();
        mBaiduMap.setMapStatus(MapStatusUpdateFactory.zoomBy(6.0f));
        mBaiduMap.setMyLocationConfigeration(new MyLocationConfiguration(MyLocationConfiguration.LocationMode.FOLLOWING, true,
                mCurrentMarker));
        xx = 0;
        Log.i("RelativeLayout", "onResume");
        ViewTreeObserver vto = fujing_title.getViewTreeObserver();
        vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if (xx < 1) {
                    xx++;
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(fujing_title.getLayoutParams());
                            params.height = MyHeight.ACTIONBAR + MyHeight.MyTitleHeight;
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                                fujing_title.setLayoutParams(params);
                            }

                        }
                    });
                }
            }
        });
        ViewTreeObserver vto1 = zoom_ll.getViewTreeObserver();
        vto1.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                if(xx<1){
                    xx++;
                    handler.post(new Runnable() {
                        @Override
                        public void run() {
                            ll_left = zoom_ll.getLeft();
                            ll_top = zoom_ll.getTop();
                        }
                    });
                }
            }
        });

        //跳转选择标签
        if(name!=null&&name.length()!=0){
            fujing_title.setText(name);
            fujing_title.setSearch_ib(android.R.drawable.ic_menu_close_clear_cancel);
            mBaiduMap.clear();
            MarkerOptions markerOptions = new MarkerOptions()
                    .position(new LatLng(latitude,longitude))
                    .icon(bitmap1);
            mBaiduMap.addOverlay(markerOptions);
        }
        getFuJing();//选择标签后
        fujing_title.setTitleViewCall(new TitleViewCall() {
            @Override
            public void Click(View view, int flag) {
                switch (flag){
                    case TitleViewCall.SEARCH:
                        CustomPage.Tag = 3;
                        MyMethod.toActivity(context, CustomPage.class);
                        break;
                    case TitleViewCall.TYPE:
                        String text=fujing_title.getType();
                        if(text.equals("求微职")){
                            fujing_title.setType("售微职");
                            type=1;
                            mBaiduMap.clear();
                            MarkerOptions markerOptions = new MarkerOptions()
                                    .position(new LatLng(latitude,longitude))
                                    .icon(bitmap1);
                            mBaiduMap.addOverlay(markerOptions);
                            getFuJing();//选择售
                        }else if(text.equals("售微职")){
                            fujing_title.setType("求微职");
                            type=0;
                            mBaiduMap.clear();
                            MarkerOptions markerOptions = new MarkerOptions()
                                    .position(new LatLng(latitude,longitude))
                                    .icon(bitmap1);
                            mBaiduMap.addOverlay(markerOptions);
                            getFuJing();//选择求
                        }
                        break;
                    case TitleViewCall.CLOSE:
                        if(fujing_title.getText()!=null&&fujing_title.getText().length()!=0){
                            name="";
                            fujing_title.setText("全部微职");
                            fujing_title.setSearch_ib(R.mipmap.search);
                            first=0;
                            second=0;
                            mBaiduMap.clear();
                            MarkerOptions markerOptions = new MarkerOptions()
                                    .position(new LatLng(latitude,longitude))
                                    .icon(bitmap1);
                            mBaiduMap.addOverlay(markerOptions);
                            getFuJing();//搜索全部
                        }
                        break;
                }
            }
        });
    }

    int type=10;
    BitmapDescriptor bitmapDescriptor;

    /**
     * 获取附近的帖子
     */
    private void getFuJing() {
        final Map<String, String> map = new HashMap<>();
        if(latitude==0&&longitude==0){
            map.put("lat", MyInfo.Latitude + "");
            map.put("lng", MyInfo.Longitude + "");
        }else{
            map.put("lat", latitude + "");
            map.put("lng", longitude + "");
        }
        if(type!=10){
            map.put("type",type+"");//求或售
        }
        map.put("isNear","1");
        map.put("raidus", 5000 + "");
        if(first!=0){
            map.put("firstCategoryId",first+"");
        }else if(second!=0){
            map.put("secondCategoryId",second+"");
        }
        MyOkHttpUtils.getInstance(context).doGet(Constants.FuJing, map)
                .excute(new MyOkHttpUtils.OKCallBack() {
                    @Override
                    public void onFailure(String message) {

                    }

                    @Override
                    public void onResponse(String message) {
                        Log.i("FuJing", "message====" + message);
                        if(message!=null){
                            try {
                                JSONObject jsonObject = new JSONObject(message);
                                boolean result = jsonObject.getBoolean("result");
                                if(result){
                                    if(list_dt!=null){
                                        list_dt.clear();
                                        Gson gson = new Gson();
                                        DiTu noteList = gson.fromJson(message, DiTu.class);
                                        list_dt = noteList.getData();
                                        if (list_dt != null && list_dt.size() != 0) {
                                            int size = list_dt.size();
                                            for (int i = 0; i < size; i++) {
                                                final double lat = list_dt.get(i).getLatitude();
                                                final double lng = list_dt.get(i).getLongitude();
                                                Log.i("FuJing", "lat===" + lat);
                                                Log.i("FuJing", "lng===" + lng);

                                                Glide.with(context).load(new GlideUrl(Constants.DOWN_USER_PICTURE + list_dt.get(i).getAvatar(), new LazyHeaders.Builder().addHeader("WZ-AUTH-TOKEN", MyInfo.Token).addHeader("WZ-AUTH-ID", MyInfo.User_Id + "").build()))
                                                        .asBitmap().into(new SimpleTarget<Bitmap>() {
                                                    @Override
                                                    public void onResourceReady(final Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
                                                        new Thread(new Runnable() {
                                                            @Override
                                                            public void run() {
                                                                Bitmap b = BitmapUtils.scaleImage(resource, 100, 100);
                                                                Bitmap bitmap = BitmapUtils.getCircleBitmap(b);
                                                                BitmapDescriptor bd = BitmapDescriptorFactory.fromBitmap(bitmap);
                                                                Message msg = new Message();
                                                                MapHelp mapHelp = new MapHelp();
                                                                mapHelp.setBd(bd);
                                                                mapHelp.setLat(lat);
                                                                mapHelp.setLng(lng);
                                                                msg.obj = mapHelp;
                                                                msg.what = 1;
                                                                handler.sendMessage(msg);
                                                            }
                                                        }).start();

                                                    }
                                                });

                                            }
                                        }
                                    }
                                }else{
                                    String msg=jsonObject.getString("message");
                                    if(msg.equals("错误的认证Token")){
                                        MyMethod.ShowDialogLogin(context,LoginActivty.class);
                                    }else{
                                        MyMethod.toActivity(context,LoginActivty.class);
                                        ((Activity)context).finish();
                                    }
                                }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }

                }

    });
    }

    /**
     * 联系他
     */
    private void TellPhone(int orderId){
        MyOkHttpUtils.getInstance(context).doGet(Constants.GetPhone+orderId+"/phone",null)
                .excute(new MyOkHttpUtils.OKCallBack() {
                    @Override
                    public void onFailure(String message) {

                    }

                    @Override
                    public void onResponse(String message) {
                        if(message!=null){
                            try {
                                JSONObject jsonObject=new JSONObject(message);
                                boolean result = jsonObject.getBoolean("result");
                                if(result){
                                    String phone = jsonObject.getString("data");
                                    daShangPopup.connect(context, fujing_rl, DaShangPopupCall.CONNECT, phone,null);
                                }else{
                                    String msg = jsonObject.getString("message");
                                    daShangPopup.connect(context, fujing_rl, DaShangPopupCall.CONNECT, null,msg);
                                }

                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    }
                });
    }

    @Override
    public void onDestroy() {
        name=null;
        // 退出时销毁定位
        mLocClient.stop();
        // 关闭定位图层
        mBaiduMap.setMyLocationEnabled(false);
        mMapView.onDestroy();
        mMapView = null;
        super.onDestroy();
    }
}
